@page "/openiddict/scopes"
@using Microsoft.AspNetCore.Authorization
@using Volo.Abp.AspNetCore.Components.Web
@using Volo.Abp.AspNetCore.Components.Web.Theming
@using Volo.Abp.AspNetCore.Components.Web.Theming.Layout
@using Volo.Abp.BlazoriseUI.Components.ObjectExtending
@using WL.Think.Abp.Dto
@using WL.Think.Abp.Localization
@using WL.Think.Abp.OpenIddict.Dtos
@using WL.Think.Abp.OpenIddict.Permission
@using WL.Think.Abp.OpenIddict.Services
@attribute [Authorize(OpenIddictPermissions.Scopes.Default)]
@inject AbpBlazorMessageLocalizerHelper<ThinkResource> LH
@inherits AbpCrudPageBase<IScopeAppService, ScopeDto, Guid, ScopePagedDto, ScopeCreateUpdateDto, ScopeCreateUpdateDto>

<Card>
    <CardHeader>
        @**************** 页头设计 ********************@
        <PageHeader Title="@L["Scopes"]"
                    BreadcrumbItems="@BreadcrumbItems"
                    Toolbar="@Toolbar">
        </PageHeader>
    </CardHeader>
    <CardBody>
        <Column ColumnSize="ColumnSize.Is4" class="form-group row" style="text-align:right;">
            <div class="col-sm-8">
                <TextEdit Placeholder="@L["Input Your Search Content"]" @bind-Text="GetListInput.Filter" Size="Size.Small"></TextEdit>
            </div>
        </Column>

        @***************** 数据表格 ************************@
        <AbpExtensibleDataGrid TItem="ScopeDto"
                               Data="@Entities"
                               ReadData="@OnDataGridReadAsync"
                               TotalItems="@TotalCount"
                               ShowPager="true"
                               PageSize="@PageSize"
                               CurrentPage="@CurrentPage"
                               Columns="@DataColumns">
        </AbpExtensibleDataGrid>
    </CardBody>
</Card>

@********************** 添加弹出框 *********************************@
@if (HasCreatePermission)
{
    <Modal @ref="CreateModal" Closing="@ClosingCreateModal">
        <ModalContent Centered="true">
            <Form>
                <ModalHeader>
                    <ModalTitle>@L[ThinkResourceNames.New]</ModalTitle>
                    <CloseButton Clicked="CloseCreateModalAsync"></CloseButton>
                </ModalHeader>
                <ModalBody>
                    <Validations @ref="@CreateValidationsRef" Model="@NewEntity" ValidateOnLoad="false">
                        <Validation MessageLocalizer="@LH.Localize">
                            <Field>
                                <FieldLabel>@L[ThinkResourceNames.Name]</FieldLabel>
                                <TextEdit @bind-Text="@NewEntity.Name" Autofocus="true">
                                    <Feedback>
                                        <ValidationError></ValidationError>
                                    </Feedback>
                                </TextEdit>
                            </Field>
                        </Validation>
                        <Validation MessageLocalizer="@LH.Localize">
                            <Field>
                                <FieldLabel>@L[ThinkResourceNames.DisplayName]</FieldLabel>
                                <TextEdit @bind-Text="@NewEntity.DisplayName" Autofocus="true">
                                    <Feedback>
                                        <ValidationError></ValidationError>
                                    </Feedback>
                                </TextEdit>
                            </Field>
                        </Validation>
                        <Field>
                            <FieldLabel>@L["Description"]</FieldLabel>
                            <TextEdit @bind-Text="@NewEntity.Description"></TextEdit>
                        </Field>
                        <Field>
                            <FieldLabel>@L[ThinkResourceNames.Resource]</FieldLabel>
                            @if (NewEntity.Resources.Any())
                            {
                                <Div Style="padding: 8px; margin-bottom: 8px; border-radius: 4px; border:solid; border-width: 1px; border-color:lightgray">
                                    @foreach (var value in NewEntity.Resources)
                                    {
                                        <Badge Color="Color.Danger" Style="margin: 4px" CloseClicked="@(() => NewEntity.Resources.Remove(value))">@value</Badge>
                                    }
                                </Div>
                            }
                            <Addons>
                                <Addon AddonType="AddonType.Body">
                                    <TextEdit Placeholder="@L["Input You Add Resource"]" @bind-Text="ResourceText" />
                                </Addon>
                                <Addon AddonType="AddonType.End">
                                    <Button Color="Color.Primary" Clicked="@AddResourceAsync">@L[ThinkResourceNames.Add]</Button>
                                </Addon>
                            </Addons>
                        </Field>
                    </Validations>
                </ModalBody>
                <ModalFooter>
                    <Button Color="Color.Primary" Outline Clicked="CloseCreateModalAsync">@L[ThinkResourceNames.Cancel]</Button>
                    <SubmitButton Clicked="@CreateEntityAsync"></SubmitButton>
                </ModalFooter>
            </Form>
        </ModalContent>

    </Modal>
}

@if (HasUpdatePermission)
{
    <Modal @ref="EditModal" Closing="@ClosingEditModal">
        <ModalContent Centered="true">
            <Form>
                <ModalHeader>
                    <ModalTitle>@L[ThinkResourceNames.Edit]</ModalTitle>
                    <CloseButton Clicked="CloseEditModalAsync"></CloseButton>
                </ModalHeader>
                <ModalBody>
                    <Validations @ref="@EditValidationsRef" Model="@EditingEntity" ValidateOnLoad="false">
                        <Validation MessageLocalizer="@LH.Localize">
                            <Field>
                                <FieldLabel>@L[ThinkResourceNames.Name]</FieldLabel>
                                <TextEdit @bind-Text="@EditingEntity.Name" Autofocus="true">
                                    <Feedback>
                                        <ValidationError></ValidationError>
                                    </Feedback>
                                </TextEdit>
                            </Field>
                        </Validation>
                        <Validation MessageLocalizer="@LH.Localize">
                            <Field>
                                <FieldLabel>@L[ThinkResourceNames.DisplayName]</FieldLabel>
                                <TextEdit @bind-Text="@EditingEntity.DisplayName" Autofocus="true">
                                    <Feedback>
                                        <ValidationError></ValidationError>
                                    </Feedback>
                                </TextEdit>
                            </Field>
                        </Validation>
                        <Field>
                            <FieldLabel>@L["Description"]</FieldLabel>
                            <TextEdit @bind-Text="@EditingEntity.Description"></TextEdit>
                        </Field>
                        <Field>
                            <FieldLabel>@L[ThinkResourceNames.Resource]</FieldLabel>
                            @if (EditingEntity.Resources.Any())
                            {
                                <Div style="padding: 8px; margin-bottom: 8px; border-radius: 4px; border:solid; border-width: 1px; border-color:lightgray">
                                    @foreach (var value in EditingEntity.Resources)
                                    {
                                        <Badge Color="Color.Danger" style="margin: 4px" CloseClicked="@(() => EditingEntity.Resources.Remove(value))">@value</Badge>
                                    }
                                </Div>
                            }
                            <Addons>
                                <Addon AddonType="AddonType.Body">
                                    <TextEdit Placeholder="@L["Input You Add Resource"]" @bind-Text="ResourceText" />
                                </Addon>
                                <Addon AddonType="AddonType.End">
                                    <Button Color="Color.Primary" Clicked="@AddResourceAsync">@L[ThinkResourceNames.Add]</Button>
                                </Addon>
                            </Addons>
                        </Field>
                    </Validations>
                </ModalBody>
                <ModalFooter>
                    <Button Color="Color.Primary" Outline Clicked="CloseEditModalAsync">@L[ThinkResourceNames.Cancel]</Button>
                    <SubmitButton Clicked="@UpdateEntityAsync"></SubmitButton>
                </ModalFooter>
            </Form>
        </ModalContent>
    </Modal>
}